package com.haredot.controller;

import com.haredot.annotation.LogIgnore;
import com.haredot.service.LogService;
import com.haredot.vo.PageVo;
import com.haredot.vo.R;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 日志模块
 */
@RestController
@RequestMapping("/log")
@LogIgnore
public class LogController {

    @Resource
    private LogService logService ;

    @GetMapping("/list")
    @PreAuthorize("hasAnyAuthority('log:opt', 'log:opt:search', 'log:opt:query')")
    public R<PageVo> queryLogger(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                 @RequestParam(value = "rows", required = false, defaultValue = "10") Integer rows,
                                 @RequestParam Map<String, Object> params) {

        PageVo pageVo = new PageVo(page, rows);

        return logService.queryLoggers(pageVo, params);
    }


    @GetMapping("/signs")
    @PreAuthorize("hasAnyAuthority('log:login', 'log:login:query')")
    public R<PageVo> querySignLogger(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                 @RequestParam(value = "rows", required = false, defaultValue = "10") Integer rows,
                                 @RequestParam Map<String, Object> params) {

        PageVo pageVo = new PageVo(page, rows);

        return logService.querySignLogger(pageVo, params);
    }
}
